package com.zdc.broad.tools

import android.graphics.Path
import android.graphics.PathMeasure
import android.graphics.PointF

class KtUtil {
    /**
     * 从一条Path中获取多少个Point点
     */
    fun getPoints(path: Path, pointCount: Int): Array<PointF?> {
        val points = arrayOfNulls<PointF>(pointCount)

        val pm = PathMeasure(path, false)
        val length = pm.length
        var distance = 0f
        val speed = length / pointCount
        var counter = 0
        val aCoordinates = FloatArray(2)
        while (distance < length && counter < pointCount) {
            // 从path中取出点Point
            pm.getPosTan(distance, aCoordinates, null)
            points[counter] = PointF(
                aCoordinates[0],
                aCoordinates[1]
            )

            counter++

            distance += speed
        }

        return points
    }
}